<div class="container-fluid" style="margin: 0px 15px 0px 15px;">
<ol class="breadcrumb">
  <li><a href="<?php echo base_url('/index.php/inicio');?>">Início</a></li>
  <li><a href="<?php echo base_url('index.php/partes/novo');?>">Parte</a></li>
  <li class="active">Consulta</li>
</ol>
	<fieldset >
	<legend>Consulta Parte</legend>
	<a data-toggle="modal"  data-target="#addparte" href="#" class="btn btn-primary btn-xs"><span class="glyphicon glyphicon-plus"></span>Adicionar Parte</a>
	<br/>
	<br/>
	<table id="example" class="display responsive nowrap" cellspacing="0" width="100%">
        <thead>
            <tr>
                
                <th class="sort-column">Nome Parte</th>
				<th data-hide="phone,tablet" class="sort-column">CPF/CNPJ</th>
                <th data-hide="phone" class="sort-column">Telefone</th>
                <th data-hide="phone" class="sort-column">Descrição</th>
                <th data-hide="phone,tablet" class="sort-column"></th>
            </tr>
        </thead>
		<tbody>
		<?php
		foreach($parte as $p){
			echo '<tr>';
			echo '<td>'.$p->nome_parte.'</td>';
			echo '<td>'.$p->cpfcnpj.'</td>';
			echo '<td>'.$p->telefone.'</td>';
			echo '<td>'.$p->descricao.'</td>';
			echo '<td><a data-toggle="modal" href="'.base_url('index.php/partes/info/'.$p->id).'" class="btn btn-success btn-xs"><span class="glyphicon glyphicon-plus"></span>Detalhes</a></td>';
		
			echo '</tr>';
		
		}
		?>
			
        </tbody>
		<tfoot class="hide-if-no-paging">
                <tr>
                    <td colspan="5">                        
					<div class="pagination pagination-centered"></div>
                    </td>
                </tr>
                </tfoot>

    </table>
			</fieldset>

		</div>
<div class="modal bs-example-modal-lg" id="addparte" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">		
		<form class='form-horizontal' role='form' id='form_parte' method="POST">
            <div class="modal-header btn-primary" >
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                 <h4 class="modal-title">Cadastro Parte</h4>
            </div>
            <div class="modal-body">
				<div class="form-group">
					<label for="" class="col-sm-2 control-label">Pessoa</label>
					<div class="col-sm-3">
						<?php 
							$tipo = array(''=>'', 'F'=>'Pessoa Física','J'=>'Pessoa Jurídica');
							echo form_dropdown('tipo',$tipo,'','class="form-control" id="tipo"');
						?>
					</div>
					<div class="col-sm-2 control-label" style="text-align:left;color:red;">
					<?php echo form_error('tipo');?>	
					</div>	
				</div>
				
				<div class="form-group">
				<label for="" class="col-sm-2 control-label">CPF/CNPJ</label>
				<div class="col-sm-2">
					<?php 
						$data = array('name'=> 'cpf_cnpj','id'=> 'cpf_cnpj','value'=>'','placeholder'=> 'CPF','class'=> 'form-control input-sm');
						echo form_input($data);
					?>
				</div>
				</div>
				<div class="form-group">
				<label for="" class="col-sm-2 control-label">Nome</label>
				<div class="col-sm-4">
					<?php 
						$data = array('name'=> 'nome_parte','id'=> 'nome_parte','value'=>'','placeholder'=> 'Nome da Parte','class'=> 'form-control input-sm');
						echo form_input($data);
						
					?>
				</div>
				<div class="col-sm-2 control-label" style="text-align:left;color:red;">
				<?php echo form_error('nome_parte');?>	
				</div>	
				</div>
				<div class="form-group">
				<label for="" class="col-sm-2 control-label">Cargo</label>
				<div class="col-sm-3">
					<?php 
						$data = array('name'=> 'cargo','id'=> 'cargo','value'=>'','placeholder'=> 'Cargo','class'=> 'form-control input-sm');
						echo form_input($data);
					?>
				</div>
				</div>
				
				<div class="form-group">
				<label for="" class="col-sm-2 control-label">Endereco</label>
				<div class="col-sm-5">
					<?php 
						$data = array('name'=> 'endereco','id'=> 'endereco','value'=>'','placeholder'=> 'endereco','class'=> 'form-control input-sm');
						echo form_input($data);
					?>
				</div>
				</div>
				<div class="form-group">
				<label for="" class="col-sm-2 control-label">Cidade</label>
				<div class="col-sm-3">
					<?php 
						$data = array('name'=> 'cidade','id'=> 'cidade','value'=>'','placeholder'=> 'Cidade','class'=> 'form-control input-sm');
						echo form_input($data);
					?>
				</div>
				</div>
				<div class="form-group">
					<label for="" class="col-sm-2 control-label">Estado</label>
					<div class="col-sm-3">
						<select class="form-control name="estado" id="estado">
							<option value="AC">Acre</option>
							<option value="AL">Alagoas</option>
							<option value="AM">Amazonas</option>
							<option value="AP">Amapá</option>
							<option value="BA">Bahia</option>
							<option value="CE">Ceará</option>
							<option value="DF">Distrito Federal</option>
							<option value="ES">Espirito Santo</option>
							<option value="GO">Goiás</option>
							<option value="MA">Maranhão</option>
							<option value="MG">Minas Gerais</option>
							<option value="MS">Mato Grosso do Sul</option>
							<option value="MT">Mato Grosso</option>
							<option value="PA">Pará</option>
							<option value="PB">Paraíba</option>
							<option value="PE">Pernambuco</option>
							<option value="PI">Piauí</option>
							<option selected value="PR">Paraná</option>
							<option value="RJ">Rio de Janeiro</option>
							<option value="RN">Rio Grande do Norte</option>
							<option value="RO">Rondônia</option>
							<option value="RR">Roraima</option>
							<option value="RS">Rio Grande do Sul</option>
							<option value="SC">Santa Catarina</option>
							<option value="SE">Sergipe</option>
							<option value="SP">São Paulo</option>
							<option value="TO">Tocantins</option>
						</select>
					</div>
					<div class="col-sm-2 control-label" style="text-align:left;color:red;">
					<?php echo form_error('tipo');?>	
					</div>	
				</div>
				<div class="form-group">
				<label for="" class="col-sm-2 control-label">Telefone</label>
				<div class="col-sm-2">
					<?php 
						$data = array('name'=> 'telefone','id'=> 'telefone','value'=>'','placeholder'=> 'Telefone','class'=> 'form-control input-sm');
						echo form_input($data);
					?>
				</div>
				</div>
			
				<div class="form-group">
				<label for="" class="col-sm-2 control-label">Descrição</label>
				<div class="col-sm-4">
					<?php 
						$data = array('name'=> 'descricao','id'=> 'descricao','placeholder'=> 'Descrição','class'=> 'form-control input-sm', 'value'=>'','rows'=>'3' );
						echo form_textarea($data);
					?>
				</div>
				</div>  
				
			</div>
				<div class="modal-footer">
				<?php 
					//$data = array('name'=>'salvar','type' => 'button','class' => 'btn btn-default','content' =>'Salvar','onclick'=>'');
					//echo form_button($data);
				?>
				<a href="#" type="button"  data-dismiss="modal" class="btn btn-default">Cancelar</a>
				 <button type="submit" class="btn btn-primary" id="modalparte" >Salvar</button>
				</div>
		</form>
    </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
	<script type="text/javascript">
		$(document).ready(function(){
			$('#example').DataTable({
				"order": [[ 0, "asc" ]],
				"language": {
					"url": "<?php echo base_url('includes/js/Portuguese-Brasil.json'); ?>"
				},
				 "pagingType": "simple"
			});
			var maskBehavior = function (val) {
					return val.replace(/\D/g, '').length === 11 ? '(00) 00000-0000' : '(00) 0000-00009';
				},
				options = {onKeyPress: function(val, e, field, options) {
						field.mask(maskBehavior.apply({}, arguments), options);
					}
				};
				//$("#telefone").mask('(99) 9999-9999');
				$("#telefone").mask(maskBehavior, options);
				$("#tipo").change(function(){
					 $('input[name=cpf_cnpj]').unmask();//Remove a mascara
					 if($(this).val()=="F"){//Acaso seja CPF
							$("input[name=cpf_cnpj]").mask("999.999.999-99");
							$("input[name=cpf_cnpj]").attr("placeholder","CPF");
					 } else {//Acaso seja Cnpj
							$("input[name=cpf_cnpj]").mask("99.999.999/9999-99");
							$("input[name=cpf_cnpj]").attr("placeholder","CNPJ");
					 }
				});
				$("#modalparte").click(function(){
					$("#form_parte").validate({
						rules: {
							tipo: "required",
							nome_parte: "required",
							cpf_cnpj: "required"
						},
						messages: {
							tipo: "Campo requerido",
							nome_parte: "Campo requerido",
							cpf_cnpj: "Campo requerido"
						},
						submitHandler: function(form){
							var dados = $('#form_parte').serialize();
							$.ajax({
									type: "POST",
									url: "<?php echo base_url('index.php/partes/salvarModal');?>",
									data: dados,
									success: function( data )
									{
										alert( data );
										$('#myModal').modal('hide');
										$('#nome_parte').val('');
										$('#cargo').val('');
										$('#descricao').val('');
										$('#cpf_cnpj').val('');
									}
							});
							return false;
						}
					});
				});
		});
	</script>
	</body>
</html>